package com.abc.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 最后我们定义一个 Util 用于获取该map中的值：
 * <p>
 * 该util需要在启动类注入进来：
 */
public class PropertiesUtil implements ApplicationContextAware {

    private static ApplicationContext applicationContext = null;

    public PropertiesUtil() {
    }

    public static CipherProperties getCipherProperties() throws JsonProcessingException {
        CipherProperties cipherProperties = applicationContext.getBean(CipherProperties.class);
        return cipherProperties;
    }

    public static WhiteListProperties getWhiteListProperties() throws JsonProcessingException {
        WhiteListProperties whiteListProperties = applicationContext.getBean(WhiteListProperties.class);
        return whiteListProperties;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (PropertiesUtil.applicationContext == null) {
            PropertiesUtil.applicationContext = applicationContext;
        }
    }
}
